package com.masterclient.app.modules.pickgoods.contract;

import com.eoner.baselib.container.CommonBaseResponse;
import com.eoner.baselib.presenter.ThrowableConsumer;
import com.masterclient.app.httpservice.RetrofitUtil2;
import com.masterclient.app.modules.pickgoods.beans.CheckOrderBean;
import com.masterclient.app.modules.pickgoods.beans.PickGoodsOrderBean;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by TMVPHelper on 2017/08/27
 */
public class PickGoodsOrderListPresenter extends PickGoodsOrderListContract.Presenter {

    @Override
    public void getPickGoodsOrderListInfo(String page,String pageSize) {
        Observable<CommonBaseResponse<PickGoodsOrderBean>> observable = RetrofitUtil2.getInstance().getPickGoodsOrderListInfo(page,pageSize);
        Disposable disposable = toSubscribe(observable, (Consumer<CommonBaseResponse<PickGoodsOrderBean>>) bean -> {
            if (bean.getCode() == 0) {
                mView.showPickGoodsOrderListInfo(bean.getData());
            } else {
                mView.showFail(bean.getMsg());
            }
        }, new ThrowableConsumer());
        mRxManager.add(disposable);
    }

    @Override
    public void orderCheck(String orderId) {
        Observable<CommonBaseResponse<CheckOrderBean>> observable = RetrofitUtil2.getInstance().orderCheck(orderId);
        Disposable disposable = toSubscribe(observable, (Consumer<CommonBaseResponse<CheckOrderBean>>) bean -> {
            if (bean.getCode() == 0) {
                mView.onCheckSuccess(bean.getData());
            } else {
                mView.onCheckFail(bean.getMsg());
            }
        }, new ThrowableConsumer());
        mRxManager.add(disposable);
    }
}